<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let product = {
        name: '华为Mate40',
        price: 3000,
        qty: 4,
        get subtotal() {
          return this.price * this.qty
        },
        info() {
          let desc = '名称：' + this.name + '价值' + this.subtotal
          console.log(desc)
        },
      }

      function Product(name) {
        this.name = name
        this.price = 0
        this.qty = 0
        this.jz = function () {
          return this.price * this.qty
        }
        this.info = function () {
          let desc = `名称：${this.name}，价值：${this.jz()}`
          console.log(desc)
        }
      }

      class Product2 {
        price = 0
        qty = 0
        constructor(name) {
          this.name = name
        }
        get jz() {
          return this.price * this.qty
        }

        info() {
          let desc = `名称：${this.name},价格：${this.jz}`
          console.log(desc)
        }
      }

      let p1 = new Product('a')
      p1.price = 200
      p1.qty = 5
      p1.info()

      let p2 = new Product2('b')
      p2.price = 200
      p2.qty = 4
      p2.info()
    </script>
  </body>
</html>
